package com.sg.hms.DaoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.sg.hms.Dao.JiesuangongziDao;
import com.sg.hms.Util.JDBCUtil;

public class JisuangongziDaoImpl implements JiesuangongziDao{

	@Override
	public int jiesuanSalary(int elId, int s_elId, java.sql.Date date, java.sql.Date salaryDate) {
		// TODO Auto-generated method stub
		int flag = 0;
		StringBuffer sql = new StringBuffer("insert into salary(elId,s_elId,date,salaryDate) values (?,?,?,?)");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, elId);
			pst.setInt(2, s_elId); 
			pst.setDate(3, date);
			pst.setDate(4, salaryDate);
			int i = pst.executeUpdate();
			if (i!=0) {
				flag = 1;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

	@Override
	public List<String> findOldSalary(int s_elId) {
		// TODO Auto-generated method stub
		List<String> list = new ArrayList<String>();
		String salaryDate = null;
		StringBuffer sql = new StringBuffer("select salaryDate from salary where s_elId=?");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, s_elId);
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				salaryDate = rs.getString("salaryDate");
				list.add(salaryDate);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

}
